<?
    require_once("mvc/action/ActionForm.php");
    require_once("mvc/action/ActionMessage.php");
    require_once("mvc/action/ActionMessages.php");

    require_once("cms/gallery/om/GalleryImage.php");


    class BaseImageForm extends ActionForm {

        protected $galleryImage;
        protected $formFile;
        protected $path;
        protected $resize1;
        protected $resize2;

        public function __construct() {
            $this->galleryImage = new GalleryImage();
            $this->formFile = null;
            $this->path = null;
            $this->resize1 = null;
            $this->resize2 = null;
        }

        public function getGalleryImage() {
            return $this->galleryImage;
        }

        public function setGalleryImage(GalleryImage $galleryImage) {
            $this->galleryImage = $galleryImage;
        }

        public function getFormFile() {
            return $this->formFile;
        }

        public function setFormFile($formFile) {
            $this->formFile = $formFile;
        }

        public function getPath() {
            return $this->path;
        }

        public function setPath($path) {
            $this->path = $path;
        }

        public function getResize1() {
            return $this->resize1;
        }

        public function setResize1($resize1) {
            $this->resize1 = $resize1;
        }

        public function getResize2() {
            return $this->resize2;
        }

        public function setResize2($resize2) {
            $this->resize2 = $resize2;
        }

        public function validate() {

            $errors = new ActionMessages();

            if(is_null($this->getGalleryImage()->getGalleryId()) || strlen($this->getGalleryImage()->getGalleryId()) == 0)
                $errors->add("galleryImage->galleryId",
                    new ActionMessage("errors.required", true, new ActionMessage("ID", false)));


            if(!is_null($this->getGalleryImage()->getGalleryId()) && strlen($this->getGalleryImage()->getGalleryId()) > 0 && strlen($this->getGalleryImage()->getGalleryId()) > 255)
                $errors->add("galleryImage->galleryId",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("ID", false),
                        new ActionMessage("255", false))));


            global $ALLOWABLE_IMAGES;
            if(!is_null($this->getFormFile()) && isset($this->formFile["size"]) && $this->formFile["size"] > 0 && !array_key_exists($this->formFile["type"], $ALLOWABLE_IMAGES))
                $errors->add("formFile",
                    new ActionMessage("errors.image", true, new ActionMessage("prompt.image", true)));

            return $errors;
        }

    }
?>